<template>
  <div>
    <el-drawer
      custom-class="learn-drawer"
      :title="this.addoredit !== 1 ? '课程新增' : '课程修改'"
      :visible.sync="drawer"
      direction="btt"
      size="100%"
      :modal="false"
      :before-close="drawerClose"
    >
      <el-container style="min-height: 100%">
        <!-- 头部 -->
        <el-header>
          <el-steps :active="step" simple>
            <el-step title="1 填写信息" icon="el-icon-edit"></el-step>
            <el-step title="2 上传资源" icon="el-icon-upload"></el-step>
            <el-step title="3 授权" icon="el-icon-s-tools"></el-step>
          </el-steps>
        </el-header>
        <!-- 内容 -->
        <el-main style="height:100px;overflow: auto">
          <!-- 第一步，填写资料 -->
          <el-row v-show="parseInt(step) === 0" :gutter="20">
            <el-col :push="4" :span="13">
              <el-form
                :model="dataForm"
                size="small"
                ref="dataForm"
                label-width="80px"
                :rules="rules"
              >
                <el-form-item label="课程名称" prop="title">
                  <el-input  v-model="dataForm.title"></el-input>
                </el-form-item>
                <el-form-item label="课程简介" prop="brief">
                  <ck-editor
                    id="drawer-ckeditor"
                    :withToolbar="false"
                    ref="ckEditor"
                    :change="contentChanged"
                  />
                </el-form-item>
                <el-form-item label="所属分类" prop="cateName">
                  <el-input
                    placeholder="请选择分类"
                    style="width: 300px;"
                    v-model="dataForm.cateName"
                    type="text"
                    readonly
                  >
                    <template slot="suffix">
                      <el-button class="el-icon-edit" @click="checkSort" type="text">选择分类</el-button>
                    </template>
                  </el-input>
                </el-form-item>
              </el-form>
            </el-col>
          </el-row>
          <!-- 第二步，上传资源 -->
          <el-row v-show="parseInt(step) === 1" :gutter="20">
            <el-col>
              <div class="learn-drawer-title">
                <h4>上传课件</h4>
                <div style="width: 240px;margin-bottom: 10px">
                  <span>
                    课件完成百分比
                    <span style="font-size: 12px">(注：考试不受百分比影响)</span>
                  </span>
                  <el-input
                    placeholder="1-100"
                    min="1"
                    max="100"
                    @input="change($event)"
                    :disabled="!!dataForm.classStatus"
                    v-model="dataForm.finishRate"
                    @keyup.native="provings"
                  >
                    <template slot="append">%</template>
                  </el-input>
                </div>
              </div>
            </el-col>
            <el-col>
              <el-table :data="uploadAll" border :span-method="arraySpanMethod" style="width: 100%">
                <el-table-column label="序号" type="index" width="80"/>
                <el-table-column label="课件名称" width="380">
                  <template slot-scope="scope">
                    <el-input
                      :disabled="!!dataForm.classStatus"
                      type="text"
                      v-model="scope.row.name"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="type" label="类型" :show-overflow-tooltip="true">
                  <template slot-scope="scope">
                    <el-tag type="info" v-if="parseInt(scope.row.type) === 1">图文</el-tag>
                    <el-tag type="info" v-if="parseInt(scope.row.type) === 2">视频</el-tag>
                    <el-tag type="info" v-if="parseInt(scope.row.type) === 3">文件</el-tag>
                    <el-tag type="info" v-if="parseInt(scope.row.type) === 4">作业</el-tag>
                    <el-tag type="info" v-if="parseInt(scope.row.type) === 5">考试</el-tag>
                  </template>
                </el-table-column>
                <el-table-column label="课件时长(秒)" width="380" prop="courseTime">
                  <template slot-scope="scope">
                    <el-input-number
                      controls-position="right"
                      :precision="0"
                      v-if="scope.row.type !=5"
                      type="number"
                      :disabled="!!dataForm.classStatus"
                      v-model="scope.row.courseTime"
                      :min="1"
                    />
                  </template>
                </el-table-column>
                <el-table-column align="right" width="288">
                  <template slot="header" slot-scope="scope" v-if="!dataForm.classStatus">
                    <el-button type="primary" @click="openUploadAll">上传课件</el-button>
                    <el-button type="primary" @click="oppton">添加考试</el-button>
                  </template>
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      v-if="scope.row.type == 5"
                      type="info"
                      title="查看"
                      @click="getExamInfo(scope.row.resourceId)"
                      circle
                      icon="el-icon-edit-outline"
                    />
                    <el-button
                      size="mini"
                      type="info"
                      v-if="!dataForm.classStatus"
                      title="向上"
                      @click="quesIndexUp(scope.$index,scope.row)"
                      circle
                      icon="el-icon-sort-up"
                    />
                    <el-button
                      size="mini"
                      type="info"
                      v-if="!dataForm.classStatus"
                      title="向下"
                      @click="quesIndexDown(scope.$index,scope.row)"
                      circle
                      icon="el-icon-sort-down"
                    />
                    <el-button
                      size="mini"
                      v-if="!dataForm.classStatus"
                      title="删除"
                      @click="handleDelete(scope.row.id)"
                      type="danger"
                      circle
                      icon="el-icon-delete"
                    />
                    <!-- <el-button  title="修改" type="primary" circle icon="el-icon-edit"/>-->
                    <!--                    <el-button title="删除" @click="handleDelete(scope.$index, uploadAll)"-->
                    <!--                               type="danger" circle icon="el-icon-delete"/>-->
                  </template>
                </el-table-column>
              </el-table>
              <span v-if="this.showResources" style="color: red">*上传资源不能为空</span>
            </el-col>
          </el-row>
          <!-- 第三步，选择范围+发布 -->
          <el-row v-show="parseInt(step) === 2" :gutter="20" class="learn-drawer-range">
            <el-col>
              <el-form :rules="rules">
                <el-form-item label="封面图" prop="imgUrl">
<!--                  :fileList="dataForm.imgUrl"-->
                  <uploader type="image" @uploaded="imageUploaded" :avatar="dataForm.imgUrl"></uploader>
                  <span>小提示：建议上传大小为250*180(px)像素图</span>
                </el-form-item>
                <el-form-item label="归档">
                  <el-tooltip content="是否归入一人一档" placement="top">
                    <el-switch
                      v-model="dataForm.putFile"
                      :active-value="1"
                      :inactive-value="0"
                      active-color="#13ce66"
                      inactive-color="#ff4949">
                    </el-switch>
                  </el-tooltip>
                </el-form-item>
                <el-form-item label prop="relateType">
                  <h4>参与人员</h4>
                  <el-radio-group v-model="dataForm.relateType">
                    <el-radio @change="kese" :label="0" border>全员参与</el-radio>
                    <el-radio :disabled="dataForm.status === 1 && dataForm.relateType === 0" :label="1" border>选人参与</el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item>
                  <el-button v-if="dataForm.relateType === 1" type="primary" @click="batchImportHandle()">批量导入
                  </el-button>
                </el-form-item>
              </el-form>
              <div
                class="learn-drawer-range-box"
                v-if="dataForm.relateType === 1"
                style="margin-top: 10px"
              >
                <p>
                  <el-tag
                    style="margin: 5px"
                    v-for="x in userList"
                    :key="x.userId"
                    @close="handleClose(x.userId)"
                    closable
                  >{{x.realname}}
                  </el-tag>
                </p>
                <div class="learn-drawer-range-box-buttons">
                  <el-button type="danger" round @click="handleCloses()">清空</el-button>
                  <el-button type="primary" round @click="openCheckPeople">添加</el-button>
                </div>
              </div>
            </el-col>
          </el-row>
          <el-dialog
            title="分类管理"
            :visible.sync="dialogFormVisible"
            :close-on-click-modal="false"
            :show-close="false"
            :close-on-press-escape="false"
            append-to-body
            width="40%"
          >
            <learn-cate
              ref="learnCate"
              v-if="learnCate"
              type="课程分类"
              :setCurrent="setCurrent"
              :current="current"
            />

            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogFormVisible = false">取 消</el-button>
              <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
            </div>
          </el-dialog>

          <el-dialog
            title="请选择新增类型"
            :visible="selectOrGroup"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            append-to-body
            width="40%"
            :before-close="_=>{this.selectOrGroup=false}"
          >
            <el-container>
              <el-main>
                <div
                  style="display: flex;align-items: center;justify-content: center;margin-bottom: 50px"
                >
                  <!--            <el-radio-group v-model="testType">-->
                  <!--              <el-radio-button :label="1">选择</el-radio-button>-->
                  <!--              <el-radio-button :label="1">正式考试</el-radio-button>-->
                  <!--              <el-radio-button :label="2">模拟考试</el-radio-button>-->
                  <!--              <el-radio-button :label="3">三违考试</el-radio-button>-->
                  <!--            </el-radio-group>-->
                  <div>请进行选择</div>
                </div>
                <ul class="select-or-group">
                  <li>
                    <el-button type="info" plain @click="selectExamFn()">选择已有试卷</el-button>
                  </li>
                  <li>
                    <el-button type="info" plain @click="groupExamFn()">选择临时组卷</el-button>
                  </li>
                </ul>
              </el-main>
            </el-container>
          </el-dialog>

        </el-main>
        <!-- 底部 -->
        <el-footer class="learn-drawer-footer">
          <el-button round type="danger" @click="drawerClose">关闭</el-button>
          <el-button v-show="parseInt(step) > 0" round type="info" @click="onBack">上一步</el-button>
          <el-button v-show="parseInt(step) < 2" round type="success"  @click="onSubmit" :loading="loading">下一步</el-button>
<!--          <el-button round type="success" v-show="parseInt(step) < 2" @click="savelesson()">保存</el-button>-->
          <!--<el-button  round type="primary" @click="onSubmit">保存</el-button>-->
          <el-button
            v-show="parseInt(step) == 2"
            round
            type="success"
            @click="release"
            :loading="loading"
          >保存
          </el-button>
        </el-footer>
      </el-container>
    </el-drawer>
    <!-- 上传课件弹出框 -->
    <uploadAll ref="uploadAll" :uploadAll="uploadAll" :setUploadAll="setUploadAll" @refreshDataList="secondStep"/>
    <!-- 课程和添加考试 -->
<!--    <addOperation-->
<!--      ref="addOperation"-->
<!--      :addOperation="addOperation"-->
<!--      :setaddOperation="setaddOperation"-->
<!--    />-->
    <!-- 选择对象弹出框 -->
    <assignAll/>
    <!-- 添加审核人弹出框 -->
    <checkPeople :checked-user-list="userList" :set-user-list="setUserList" ref="checkPeople"/>
    <!--    批量导入-->
    <batch-import
      v-if="batchImportVisible"
      ref="batchImport"
      @uploadFile="uploadFile"
    />
    <el-drawer
      title="选择已有试卷"
      :visible="select"
      direction="btt"
      :before-close="_=>{this.select=false}"
      size="100%"
      custom-class="drawer-box"
    >
      <el-card class="kxy-card">
        <paper
          type="list"
          :setExamRow="setExamRow"
          :handleClose="_=>{this.select=false}"
          :setExam="setExam"
        />
      </el-card>
    </el-drawer>
    <el-drawer
      title="配置信息"
      custom-class="drawer-box"
      :append-to-body="true"
      :visible="examInfoDrawer"
      size="80%"
      :close-on-press-escape="false"
      :show-close="false"
      :wrapperClosable="false"
    >
      <exam-info-form
        ref="examInfoForm"
        @refreshDataList="secondStep"
        :examInfoFormSubmit="examInfoFormSubmit"
        :setTestType="setTestType"
        :selectExamFn="selectExamFn"
        :testType="testType"
        :handleClose="_=>{this.examInfoDrawer = false}"
        :setExamRow="setExamRow"
        :examRow="examRow"
      />
    </el-drawer>
    <add-exam
      ref="groupExam"
      v-show="groupExam"
      :setExamRow="setExamRow"
      :setExam="setExam"
      :testType="testType"
      :setaddOperation="setaddOperation"
    />
<!--     选择已有试卷-->
    <!--      url="/exam-admin/ques/import/singer"-->
  </div>
</template>

<script>
  import BatchImport from '../modules/questions/batchimport'
  import assignPeople from '../../components/assign/assignPeople'
  import assignAll from '../../components/assign/assignAll'
  import selectTopic from '../../components/check/selectTopic'
  import addOperation from '../../components/check/addOperation'
  import uploadAll from '../../components/upload/uploadAll'
  import uploadCover from '../../components/upload/uploadCover'
  import checkPeople from '../../components/check/checkPeople'
  import AddExam from '../../components/check/addExam'
  import CkEditor from '../../components/ckEditor/ckEditor'
  import paper from '../modules/paper/paper'
  import ExamInfoForm from '../modules/exam/exam-info-form'
  // import Vue from 'vue'
  // import Uploader from '@/components/uploader'
  import Uploader from '@/components/uploader/avatar-uploader'
  import learnCate from '../../views/modules/learn/learncate'

  export default {
    name: 'drawer',
    data() {
      return {
        groupExam: false,
        testType: 1,
        examInfoDrawer: false,
        batchImportVisible: false,
        loading: false,
        dialogFormVisible: false,
        learnCate: false,
        selectOrGroup: false,
        select: false,
        value: 0,
        showResources: false,
        userList: [],
        endTime: '',
        addoredit: 1,
        step: 0,
        current: {},
        formInline: {
          user: '',
          region: ''
        },
        examRow: {
          paperName: '',
          id: null
        },
        courseId: '',
        dataForm: {
          cateId: '',
          title: '',
          classHour: '',
          classStatus: '',
          brief: '',
          creditHour: '',
          putFile: 0,
          startTime: '',
          endTime: '',
          cateName: '',
          imgOssId: '',
          courseTime: '',
          imgUrl: '',
          status: 0,
          relateType: 0,
          id: '',
          resourceId: null,
          finishRate: 80,
          userList: [],
          type: {
            image: 1,
            video: 2
          }
        },
        nextshow: true,
        props: {
          label: 'name',
          children: 'zones',
          isLeaf: 'leaf'
        },
        operationDialogVisible: false,
        examDialogVisible: false,
        drawer: false,
        rules: {
          title: [{required: true, message: '请输入课程名称', trigger: 'blur'}],
          cateId: [
            {required: true, message: '请选择课程分类', trigger: 'change'}
          ],
          brief: [{required: true, message: '简介不能为空', trigger: 'change'}],
          cateName: [{required: true, message: '分类不能为空', trigger: 'change'}],
          imgUrl: [{required: true, message: '主图不能为空', trigger: 'change'}]
        },
        uploadAll: [],
        addOperation: []
      }
    },
    props: ['getDataList'],
    methods: {
      change(e) {
        this.$forceUpdate()
      },
      examInfoFormSubmit() {
        this.examInfoDrawer = false
        this.$refs.groupExam.examDialogVisible = false
        this.select = false
        this.selectOrGroup = false
        this.getDataList(1)
      },
      setTestType(val) {
        this.testType = val
      },
      selectExamFn() {
        this.select = true
      },
      // 选择临时组卷
      groupExamFn(data) {
        this.group = true
        this.groupExam = true
        this.$nextTick(_ => this.$refs.groupExam.init(data))
      },
      setExam() {
        if (this.examRow && this.examRow.paperName) {
          this.getExamInfo()
        } else {
          this.$notify.error({
            title: '错误',
            message: '请先选择试卷'
          })
        }
      },
      // 修改
      getExamInfo(id) {
        if (this.examInfoDrawer) {
          this.select = false
        } else {
          this.examInfoDrawer = true
          this.$nextTick(_ => {
            this.$refs.examInfoForm.getExamInfo(id, 2, this.dataForm.id)
          })
        }
      },

      setExamRow(val) {
        this.examRow = val
      },
      contentChanged(val) {
        this.dataForm.brief = val
      },
      // 正整数检验
      provings() {
        // eslint-disable-next-line no-useless-escape
        this.dataForm.finishRate = this.dataForm.finishRate.replace(/[^.\d]/g, '')
        this.dataForm.finishRate = this.dataForm.finishRate.replace('.', '')
      },
      setUserList(data) {
        data.forEach(user => {
          if (this.userList.findIndex(x => x.userId === user.userId) === -1) {
            this.userList.push(user)
          }
        })
      },
      // 批量导入
      batchImportHandle() {
        this.batchImportVisible = true
        this.$nextTick(() => {
          this.$refs.batchImport.init(7)
        })
      },
      // 导入后文件处理
      async uploadFile(file) {
        let Loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(255, 255, 255, 0.7)'
        })
        let data = new FormData()
        data.append('file', file)
        let res = await this.$http.post('/usercenter-admin/import/importPublisherUser', data)
        Loading.close()

        if (res && res.code === 200) {
          this.$notify.success({title: '成功', message: '导入成功'})
          this.userList = res.data.userList
          this.batchImportVisible = false
        } else {
          this.$notify.error({title: '错误', message: res.msg})
        }
      },
      // 删除
      Delete(e) {
        this.$confirm('删除后所有有关信息都会删除', '提示', {
          confirmButtonText: '删除',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            this.$http({
              url: this.$http.adornUrl('/train-admin/course/deletecourseexam'),
              method: 'post',
              data: this.$http.adornParams({
                id: e.row.resourceId
              })
            }).then(data => {
              if (data && data.code === 200) {
                this.$notify.success({
                  title: '提示',
                  message: '操作成功'
                })
                this.uploadAll.splice(this.uploadAll.indexOf(e.$index), 1)
              } else {
                this.$notify.warning({
                  title: '提示',
                  message: data.msg
                })
              }
            })
          })
          .catch(_ => {
            this.$notify.info({
              title: '提示',
              message: '已取消删除'
            })
          })
      },
      // 分类
      setCurrent(data) {
        this.dataForm.cateId = data.id
        this.dataForm.cateName = data.name
        if (data.id) this.current = data
      },
      checkSort() {
        this.learnCate = true
        this.dialogFormVisible = true
        this.$nextTick(() => {
          this.$refs.learnCate.init()
        })
      },
      // 添加人员
      openCheckPeople() {
        this.$refs['checkPeople'].init(this.dataForm.userList)
      },
      openUploadAll() {
        this.$refs['uploadAll'].init(this.dataForm.id)
      },
      oppton() {
        this.selectOrGroup = true
      },
      // 原随机组卷
      // openAddOperation(e, scope) {
      //   if (scope) {
      //     this.$refs['addOperation'].init(scope.row.resourceId, scope.$index)
      //   } else {
      //     this.$refs['addOperation'].init()
      //   }
      // },
      drawerClose() {
        this.step = 0
        this.drawer = false
      },
      // 人员列表删除
      handleClose(userId) {
        var index = this.userList.findIndex(x => x.userId === userId)
        this.userList.splice(index, 1)
      },
      kese() {
        this.handleCloses()
      },
      handleCloses() {
        // this.dataForm.userList = []
        this.userList = []
      },
      // 向上，向下
      quesIndexUp(index, row) {
        var that = this
        if (index > 0) {
          let upDate = that.uploadAll[index - 1]
          that.uploadAll.splice(index - 1, 1)
          that.uploadAll.splice(index, 0, upDate)
        } else {
          alert('已经是第一条，不可上移')
        }
      },
      quesIndexDown(index, row) {
        var that = this
        if (index + 1 === that.uploadAll.length) {
          alert('已经是最后一条，不可下移')
        } else {
          let downDate = that.uploadAll[index + 1]
          that.uploadAll.splice(index + 1, 1)
          that.uploadAll.splice(index, 0, downDate)
        }
      },
      // 上传资源删除当前行
      // handleDelete(index, rows) {
      //   rows.splice(index, 1)
      // },
      handleDelete(id) {
        console.log(id)
        // var ids = id ? [id] : this.dataListSelections.map(item => {
        //   return item.id
        // })
        // this.fullscreenLoading = true
        this.$confirm(`确定要进行删除操作吗？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/train-admin/course/delCourseResource'),
            method: 'post',
            data: { id: id }
          }).then(res => {
            if (res && res.code === 200) {
              this.$notify({
                title: '成功',
                message: '删除成功',
                type: 'success'
              })
              this.secondStep()
            } else {
              this.$notify.error({
                title: '提示',
                message: res.msg
              })
            }
          })
        })
      },
      init(id, classStatus, addoredit) {
        this.addoredit = addoredit
        this.dataForm.classStatus = classStatus
        if (id) {
          this.firstStepInfo(id)
        } else {
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.$refs.ckEditor.setData('')
          })
        }
        this.nextshow = true
        this.dataForm.id = id
        this.uploadAll = []
        this.step = 0
        this.drawer = true
      },
      setUploadAll(data) {
        this.uploadAll = this.uploadAll.concat(
          data.map(x => ({
            resourceId: this.dataForm.resourceId,
            name: x.name,
            resourceUrl: x.url,
            type: x.type,
            courseTime: this.dataForm.courseTime
          }))
        )
      },
      setaddOperation(data, index) {
        if (
          index !== null &&
          index !== '' &&
          index !== undefined &&
          data.courseExamId === this.uploadAll[index].resourceId
        ) {
          this.uploadAll.splice(index, 1, {
            resourceId: data.courseExamId,
            name: data.name,
            type: data.type
          })
          this.$forceUpdate()
        } else {
          this.dataForm.resourceId = data.courseExamId
          var sss = {
            resourceId: data.courseExamId,
            name: data.name,
            type: data.type
          }
          this.uploadAll.push(sss)
        }
      },
      onBack() {
        switch (this.step) {
          case 2:
            this.step = 1
            break
          case 1:
            this.step = 0
            break
          default:
            break
        }
      },
      // 上传主图
      imageUploaded(file) {
        this.dataForm.imgUrl = file.url
      },
      // 上传主图
      handleImgSuccess(res, file) {
        this.dataForm.imgOssId = res.data.id
      },
      beforeImgUpload(file) {
        let isJPG = file.type.split('/')[0] === 'image'
        const isLt2M = file.size / 1024 / 1024 < 2

        if (!isJPG) {
          this.$message.warning('只能上传图片格式!')
        }
        if (!isLt2M) {
          this.$message.warning('上传图片大小不能超过 2MB!')
        }
        return isJPG && isLt2M
      },
      handleImgRemove() {
        this.dataForm.mainImg = ''
        this.dataForm.mainImgUrl = []
      },
      async firstStepInfo (id) {
        var data = await this.$http.post('/train-admin/course/firstStepInfo', {
          id: id
        })
        if (data.code === 200) {
          this.$refs.ckEditor && this.$refs.ckEditor.setData(data.data.brief)
          this.dataForm.title = data.data.title
          // this.dataForm.brief = data.data.brief
          this.dataForm.cateId = data.data.cateId
          this.dataForm.cateName = data.data.cateName
        }
      },
      async onSubmit() {
        switch (this.step) {
          case 0:
            this.$refs['dataForm'].validate(valid => {
              if (valid) {
                this.courseDetail()
              }
            })
            break
          case 1:
            if (this.uploadAll.length > 0) {
              this.secondStepsave()
            } else {
              this.showResources = true
              return false
            }
            break
          default:
            break
        }
      },
      // 简单详情
      async courseDetail () {
        this.loading = true
        var res = await this.$http.post('/train-admin/course/firstStep', {
          id: this.dataForm.id ? this.dataForm.id : '',
          title: this.dataForm.title,
          brief: this.dataForm.brief,
          cateId: this.dataForm.cateId
        })
        if (res.code === 200) {
          this.loading = false
          this.dataForm.id = res.data
          this.nextshow = false
          this.step = 1
          this.getDataList()
          if (this.step === 1) {
            this.secondStep()
          }
        } else {
          this.loading = false
          return false
        }
      },
      // 第二步保存
      async secondStepsave() {
        this.loading = true
        var res = await this.$http.post('/train-admin/course/secondStep', {
          finishRate: this.dataForm.finishRate ? this.dataForm.finishRate : 80,
          courseId: this.dataForm.id ? this.dataForm.id : '',
          resourcesJson: JSON.stringify(this.uploadAll)
        })

        if (res.code === 200) {
          this.step = 2
          this.thirdStepInfo()
          this.loading = false
          this.nextshow = false
          this.getDataList()
        } else {
          this.loading = false
        }
      },
      // 第二步详情
      async secondStep() {
        this.showResources = false
        var res = await this.$http.post('/train-admin/course/secondStepInfo', {
          courseId: this.dataForm.id ? this.dataForm.id : ''
        })
        if (res.code === 200) {
          this.dataForm.finishRate = res.data.finishRate
          this.uploadAll = res.data.resourceList
          if (this.uploadAll.length > 0) {
            this.showResources = false
          }
        }
      },
      // 第三步详情
      async thirdStepInfo() {
        this.dataListLoading = true
        let res = await this.$http.post('/train-admin/course/thirdStepInfo', {
          courseId: this.dataForm.id ? this.dataForm.id : ''
        })

        if (res.code === 200) {
          this.dataForm.status = res.data.status
          this.dataForm.imgUrl = res.data.imgUrl === null ? '' : res.data.imgUrl
          this.userList = res.data.users
          this.dataForm.putFile = res.data.putFile
          this.dataForm.relateType = res.data.relateType
          // this.$set(this.dataForm, 'relateType', data.data.relateType)
        }
        // this.$http({
        //   url: this.$http.adornUrl('/train-admin/course/thirdStepInfo'),
        //   method: 'post',
        //   data: {
        //     courseId: this.dataForm.id ? this.dataForm.id : ''
        //   }
        // }).then(data => {
        //   if (data.code === 200) {
        //     this.dataForm.status = data.data.status
        //     this.dataForm.imgUrl = data.data.imgUrl === null ? '' : data.data.imgUrl
        //     this.userList = data.data.users
        //     this.dataForm.relateType = data.data.relateType
        //     // this.$set(this.dataForm, 'relateType', data.data.relateType)
        //   }
        // })
      },
      // 第三步保存
      release() {
        // eslint-disable-next-line eqeqeq
        if (this.dataForm.imgUrl === '' || this.dataForm.imgUrl === null) {
          this.$notify.error({
            title: '错误',
            message: '封面图不能为空'
          })
          return false
        }
        // this.loading = truefeng
        // eslint-disable-next-line eqeqeq
        this.$http({
          url: this.$http.adornUrl(
            `/train-admin/course/thirdStep`
          ),
          method: 'post',
          data: this.$http.adornData({
            courseId: this.dataForm.id,
            putFile: this.dataForm.putFile,
            imgUrl: this.dataForm.imgUrl,
            relateType: this.dataForm.relateType,
            userIds: this.dataForm.userList ? this.dataForm.userList.map(x => x).join(',') : []
          })
        }).then(data => {
          console.log(data)
          if (data && data.code === 200) {
            this.drawer = false
            this.getDataList()
          } else {
            this.$notify.error({
              title: '错误',
              message: data.msg
            })
          }
          this.loading = false
        })
      },
      arraySpanMethod({row, column, rowIndex, columnIndex}) {
        // console.log(this.tableData.length)
        // console.log({row, column, rowIndex, columnIndex})
      }
    },
    components: {
      AddExam,
      assignPeople,
      assignAll,
      selectTopic,
      addOperation,
      uploadAll,
      uploadCover,
      checkPeople,
      Uploader,
      learnCate,
      BatchImport,
      ExamInfoForm,
      CkEditor,
      paper
    },
    watch: {
      'userList'(val) {
        console.log(val)
        this.dataForm.userList = val.map(x => x.userId)
      }
    },
    // 日期转换为时间戳
    getTimestamp(time) {
      return new Date(time).getTime()
    },

    // 时间戳转为日期并截取时间部分
    getDate(value) {
      let year = new Date().getFullYear()
      let month = new Date().getMonth()
      let day = new Date().getDate()
      return year + '-' + (month + 1) + '-' + day + ' ' + value
    }
  }
</script>

<style>
  #drawer-ckeditor .ck-toolbar {
    display: none !important;
  }
  .select-or-group {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    justify-content: space-around;
    align-items: center;
  }

  .select-or-group > li {
    flex: 1;
    font-size: 14px;
    text-align: center;
  }
</style>
